package logic

import (
	"activity_srv/activity"
	"activity_srv/internal/dao"
	"activity_srv/internal/svc"
	"context"
	"go.uber.org/zap"
	"smart-health-platforms/pkg"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetDistributionLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGetDistributionLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetDistributionLogic {
	return &GetDistributionLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 获取分销设置信息
func (l *GetDistributionLogic) GetDistribution(in *activity.GetDistributionRequest) (*activity.GetDistributionResponse, error) {
	//业务逻辑
	distribution, err := dao.GetDistribution(in)
	if err != nil {
		pkg.Error("获取分销设置详情失败", zap.Error(err))
		return nil, err
	}

	return &activity.GetDistributionResponse{
		Distribution:     int64(distribution.Id),
		FirstLevelRatio:  float32(distribution.FirstLevelRatio),
		SecondLevelRatio: float32(distribution.SecondLevelRatio),
		MinWithdraw:      float32(distribution.MinWithdraw),
		WithdrawFee:      float32(distribution.WithdrawFee),
		Status:           int64(distribution.Status),
	}, nil
}
